import { myName, h, print, println, sayHi, whitchStr, add, Person } from "hello"
import { Student } from "jicheng"
import { add2 } from "fanxing"
import { SoundManager } from "danli"
import DataType from "./DataType"
import { good1, good2 } from './Inface'

console.log("TypeScript测试项目");
console.log(myName());

document.body.innerHTML = "你好！" + myName();
print(myName());
print(h());

println("hello typescript");
println(sayHi("yejing"));



let a = 10;
let b = 20;
const c = 30;
let s = a + b;
let n = c - a;
document.write("<br>");
document.write(s + "");
document.write("<br>");
document.write(n + "");
document.write("<br>");
document.write(s++ + "");// 先使用，再自增，这里其实已经是31了
document.write("<br>");
document.write(++s + "");// 先自增，再使用，这里就是32了

println("==============条件语句==============")
let res: boolean = false;
if (res) {
    print("true");
} else {
    print("false");
}


println("==============switch==============")
enum Color {
    RED,
    BLOW,
    GREEN
}

const cor: Color = Color.RED;
function testSwitch() {
    switch (cor) {
        case Color.RED:
            print("红色")
            break;
        case Color.BLOW:
            println("蓝色")
            break;
        case Color.GREEN:
            println("绿色")
            break;
        default:
            println("红色")
    }
}

testSwitch()


let number = 20;
switch (number) {
    //switch cases without break statements  
    case 10: println("10");
    case 20: println("20");
    case 30: println("30");
    default: println("Not in 10, 20 or 30");
}

println("==============switch==============")

enum Direction {
    East,
    West,
    North,
    South
};
var dir: Direction = Direction.North;

function getDirection() {
    switch (dir) {
        case Direction.North: console.log('You are in North Direction');
            break;
        case Direction.East: console.log('You are in East Direction');
            break;
        case Direction.South: console.log('You are in South Direction');
            break;
        case Direction.West: console.log('You are in West Direction');
            break;
    }
}
getDirection();

let cstr = whitchStr("d");
println(cstr)

let x = add(4, 5)
println(x + "")

let p1 = new Person("zhangsan", 45);
p1.age = 45;
p1.name = "zhangsan";
p1.say()

let p2 = new Person("ybq", 56);
p2.name = "ybq"
p2.age = 56
p2.say()

Person.showDesc()

let stu1 = new Student("张三", 24)
stu1.no = "123456"
stu1.score = 24
stu1.say()

let value = add2<number>(4)
println(value + "")

println("==============元祖的使用==============")
// 元组,类似于数组，多个数据，可以不同的数据类型，用下标进行访问
let hero: [string, number] = ["yejing", 34]
println(hero[0] + " " + hero[1])
println("==============数组的使用==============")
// 数组
let nu: number[] = [1, 2, 3, 4, 5, 6]
for (let i = 0; i < nu.length; i++) {
    println(nu[i] + "")
}
println("==============字典的使用==============")
// 字典
let dct: { [key: string]: string } = {
    "name": "yejing",
    "name2": "wangxiaomao"
}
println(dct["name2"])

println("==============回调==============")
// 回调,参数是一个函数
function fc(test: Function) {
    test()
}

function test() {
    println("test1")
}

// 传递函数名
fc(test)

// 匿名函数
fc(() => {
    println("test2")
})

// 匿名函数
fc(function () {
    println("test3")
})


// 单例对象

let sm = SoundManager.Instance()


println("==============观察者模式==============")
// 代理模式
interface ICalc {
    calc(num1, num2): number;
}

class Npc1 implements ICalc {
    calc(num1, num2): number {
        return num1 + num2;
    }
}

class Npc2 implements ICalc {
    calc(num1, num2): number {
        return num1 - num2;
    }
}

// 观察者接口
interface Iobserver {
    nameChanged(newName: string);
}

// 监听者
class Test implements Iobserver {
    nameChanged(newName: string) {
        println("监听到变化，名字变为 " + newName)
    }
}

class Person2 {
    private _name: string
    observers: Array<Iobserver> = new Array<Iobserver>();

    set name(value) {
        this._name = value
        for (let observer of this.observers) {
            observer.nameChanged(this._name)
        }
    }

    delegate: ICalc;
    GetNumm(num1, num2) {
        let num = this.delegate.calc(num1, num2)
        println(num + "")
    }
}

let p = new Person2();
let tst = new Test();
p.observers.push(tst)
p.name = "张三"
p.name = "王小毛"
p.delegate = new Npc2() // 通过这个去计算
p.GetNumm(4, 5)


// 工厂模式


// 使用命名空间
println("==============命名空间==============")
import { createP } from "./namespaceDemo";
let p3 = createP()
p3.sayLan();


/////

DataType.aaa()
good1.func()
good2.func()


